package com.zhengke.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhengke.common.dao.CommonDao;
import com.zhengke.common.object.Result;
import com.zhengke.dao.OrderDao;
import com.zhengke.pojo.Order;
import com.zhengke.pojo.Sth;
import com.zhengke.pojo.TvOrder;

@Service
public class OrderServiceImpl implements OrderService {
	
	@Autowired
	OrderDao od;
    
	@Autowired
	private CommonDao dao;
	@SuppressWarnings("unchecked")
	@Override
	public Result queryAll(String orderSn, String userId, String userName, String orderState,int pageNum,int size) throws Exception {
		Map<String,String> param = new HashMap<String,String>();
		param.put("orderSn", orderSn);
		param.put("userId", userId);
		param.put("userName", userName);
		param.put("orderState", orderState);
		
		PageHelper.startPage(pageNum, size, true);
		
		List<TvOrder> rtnList = (List<TvOrder>)dao.findForList("orderMapper.queryOrder", param);
		PageInfo<TvOrder> pageInfo = new PageInfo<TvOrder>(rtnList);
		
		Result rs = new Result();
		rs.setCode("0");
		rs.setCount(pageInfo.getTotal());
        rs.setData(rtnList);		
		return rs;
	}
	/**
	 * 刘浩
	 */
	@Override
	public Result selectOrder(Sth sth) {
		PageHelper.startPage(sth.getPage(),sth.getLimit(),true);
		List<Order> orderList = od.selectOrder(sth);
		PageInfo<Order> pageInfo = new PageInfo<Order>(orderList);
		Result rs = new Result();
		rs.setCount(pageInfo.getTotal());
		rs.setData(orderList);
		rs.setCode("0");
		rs.setMsg("success");
		return rs;
	}

	/**
	 * 根据订单id查询订单信息
	 */
	@Override
	public TvOrder queryObjByOrderId(Integer orderId) throws Exception {
		return (TvOrder) dao.findForObject("orderMapper.queryObjByOrderId",orderId);
	}

}
